package com.huixh.train.business.controller.admin;

import com.huixh.train.business.req.TrainCarriageQueryReq;
import com.huixh.train.business.req.TrainCarriageSaveReq;
import com.huixh.train.business.resp.TrainCarriageQueryResp;
import com.huixh.train.business.service.TrainCarriageService;
import com.huixh.train.common.resp.PageResult;
import com.huixh.train.common.resp.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huixh
 */
@Validated
@RestController
@RequestMapping("/admin/trainCarriage")
@Tag(name = "列车车厢管理", description = "列车车厢管理")
public class TrainCarriageController {
    @Resource
    private TrainCarriageService trainCarriageService;

    @PostMapping("/save")
    @Operation(summary = "新增车厢", method = "POST")
    public Result<?> save(@RequestBody @Valid TrainCarriageSaveReq trainCarriageSaveReq) {
        trainCarriageService.save(trainCarriageSaveReq);
        return Result.success();
    }

    @PostMapping("/quest-list")
    @Operation(summary = "查询车厢列表", method = "POST")
    public PageResult<List<TrainCarriageQueryResp>> query(@RequestBody @Valid TrainCarriageQueryReq trainCarriageQueryReq) {
        return trainCarriageService.queryList(trainCarriageQueryReq);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除车厢", method = "DELETE")
    public Result<?> deleteById(@NotNull @PathVariable(name = "id") Long id) {
        trainCarriageService.delete(id);
        return Result.success("删除成功");
    }

}